#ifndef ____Mavlink_H____
#define ____Mavlink_H____

#include <map>
#include "Format.h"

struct MavlinkCfg
{
    unsigned char length;
    unsigned char id;
    std::string xml;
    CFormat fmt;
};

typedef std::map<int, MavlinkCfg> MapMavlinkCfg;

class CMavlink
{
public:
    CMavlink();
    ~CMavlink() {};

    void print();
    std::vector<unsigned char> encode(int msgid);
    int encode(int msgid, std::vector<unsigned char> &data);
    int decode(const std::vector<unsigned char> &data);
    int decode(const unsigned char *p, int nSize);
    inline CFormat &get() { return fmt; }
    CFormat &get(int msgid);

private:
    void load(const std::string &strXml);

private:
    CFormat fmt;
    static MapMavlinkCfg mapMavlinkCfg;
};

unsigned short crc16_mcrf4xx(const unsigned char *data, size_t len);

#endif // ____Mavlink_H____
